import React from 'react';

import {

} from 'react-native';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import Config from '../../config';
import CommonCheckUserTypeAction from './CommonCheckUserTypeAction';

export default class JumpToPageByUrlAction extends BaseAction {
  constructor() {
    super();
    this.moduleType = Constants.MODULE_TYPE.COMMON;
    this.name = "JumpToPageByUrlAction";
  }

  finish(data) {
    if(data.link === undefined || data.link === "") {
      return;
    }
    let linkArr = data.link.split(";");
    let jumpType = linkArr[0];
    // jumpType = "news_topics";
    let jumpData = linkArr.length > 1 ? linkArr[1] : -1001;
    if(jumpType == Constants.MODULE_TYPE.ACTIVITY) {
      this.caller.gotoPage(Config.pages.activity_content, {activity_id:jumpData});
    }
    else if (jumpType == Constants.MODULE_TYPE.WORK_HARD) {
      this.caller.gotoPage(Config.pages.wh_content, {post_id:jumpData});
    }
    else if (jumpType == "news") {
      this.caller.gotoPage(Config.pages.news_content, {news_id:jumpData});
    }
     else if (jumpType == "new") {//新闻
      this.caller.gotoPage(Config.pages.news_content, {news_id:jumpData});
    }
    else if (jumpType == "heartConsult") {
      //预约咨询
      this.caller.gotoPage(Config.pages.heart_expert_data, {expert_id:jumpData,type:1});
    }
    else if(jumpType == "heartStore"){
      this.caller.gotoPage(Config.pages.zhp_content, {post_id:jumpData,board_id:3});
      // this.caller.gotoPage
    }
    else if (jumpType == "heartEAP") {
      //预约咨询
      this.caller.gotoPage(Config.pages.heart_eap_content, {activity_id:jumpData});
    }
    else if(jumpType === "heart_test_web") {
      new CommonCheckUserTypeAction().call(this.caller, {needLogin:true, needVerify:true}, () => this._onCheckUserTypeCallback(jumpType))
    }
    else if(jumpType == "url"){
      if(jumpData.indexOf("http://") == -1 && jumpData.indexOf("https://") == -1)
      {
        jumpData = "http://" + jumpData;
      }
      this.caller.gotoPage(Config.pages.ad_Webview, {url:jumpData});
    }
    else if(jumpType === "new_special") {
      this.caller.gotoPage(Config.pages.news_topics, {topicData:data});
    }
  }

  _onCheckUserTypeCallback(jumpType) {
    if(jumpType === "heart_test_web") {
      this.caller.gotoPage(Config.pages.heart_test_web);
    }
  }
}
